home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Sapphire Collection / Software Vault (Sapphire Collection) (Digital Impact).ISO / cdr47 / trace122.zip / TRACE11.ASM < prev    next >
Assembly Source File  |  1997-02-13  |  43KB  |  1,427 lines

  1.            page    60,132
  2.            .lfcond
  3.            title   "TRACE - Interrupt Tracer"
  4.            subttl  Introduction
  5.            page
  6. code       segment para public 'code'
  7.            assume  cs:code,ds:code
  8.            public  selvideo,selprint,print,print_hex,print_word,print_wordb
  9.            public  crlf,print_line,print_seg,print_edit,print_dec,table_print
  10.            public  feed,key,zap_hits,prt_sc
  11.  
  12.            extrn   prt_base:word,trace_table:byte,trace_curr:word,ict_index:word
  13.  
  14.            public  pick_ict,do_traces,do_enable,do_fcb,dump_buf,bin_to_bit
  15.            public  dump_rec,dump_before,dump_after,dump_flags,dump_fcb
  16.            public  dump_asciiz,ict_dump,disp_active
  17.  
  18.            extrn   rec_sizes:word,interp:near
  19.            extrn   old_int_5:dword
  20.  
  21.            include b:trace1e.aic
  22.  
  23. prt_flag   db   0                    ;flag: printer (1) or Screen (2) 
  24.            subttl  Support routines - Printer & Screen I/O
  25.            page
  26. ;*****************************************
  27. ;
  28. ; Select video for subsequent output
  29. ;
  30. ;*****************************************
  31.  
  32. selvmsg  db      cr,lf,"TRACE output routed to CRT screen",cr,lf,"$"
  33. selvideo proc    near
  34.          mov     prt_flag,0
  35.          push    dx
  36.          mov     dx,offset selvmsg
  37.          call    print_line
  38.          pop     dx
  39.          ret
  40. selvideo endp
  41.  
  42.  
  43. ;*****************************************
  44. ;
  45. ; Select printer for subsequent output
  46. ;
  47. ;*****************************************
  48.  
  49. selpmsg    db    cr,lf,"TRACE output routed to printer",cr,lf,"$"
  50. selpnomsg  db    cr,lf,"Printer not found",cr,lf,"$"
  51. selprint proc    near
  52.          push    ax
  53.          mov     ax,prt_base     ;do we have a printer?
  54.          or      al,ah
  55.          jz      selprint_no_printer
  56.  
  57.          push    dx
  58.          mov     dx,offset selpmsg
  59.          call    print_line
  60.          pop     dx
  61.          mov     prt_flag,al     ;al is non-zero if we do
  62.          jmp     selprint_exit
  63. selprint_no_printer:
  64.          push    dx
  65.          mov     dx,offset selpnomsg
  66.          call    print_line
  67.          pop     dx
  68. selprint_exit:
  69.          pop     ax
  70.          ret
  71. selprint endp
  72.  
  73. ;********************************************************
  74. ;
  75. ; Output AL to printer or screen, depending on prt_flag.
  76. ;
  77. ;********************************************************
  78.  
  79. print   proc    near
  80.         push    dx
  81.         push    cx
  82.         push    bx
  83.         push    ax
  84.  
  85. ; ----- See if it should go to printer
  86.  
  87.         test    prt_flag,0ffh           ;send it to printer?
  88.         jnz     print1                  ;yes
  89.  
  90. print0:
  91.  
  92. ;
  93. ; Send char to video via INT 010H
  94. ;
  95.  
  96.         mov     bl,1
  97.         mov     ah,14                   ;"Write TTY" func
  98.         int     010h
  99.         clc                             ;show no I/O error
  100.         jmp     short print9
  101.  
  102. print1:
  103.  
  104. ;----- Send it to printer
  105.  
  106.         mov     dx,prt_base             ;get printer base I/O address
  107.         inc     dx                      ;up to status port
  108.         mov     ah,al                   ;save char in ah
  109.         xor     cx,cx                   ;init timeout ticker
  110.  
  111. print2:
  112.         in      al,dx                   ;get status
  113.         test    al,080h                 ;is printer busy?
  114.         jnz     print5                  ;no, proceed to send char
  115.  
  116. ;
  117. ; We're not immediately ready. Some printers require more of a wait than
  118. ; the simple 64K loop found in CX. So here's a time waster that you may
  119. ; want to tailor to your printer.
  120. ;
  121.  
  122.         mov     al,8                    ;greatly extend timeout value
  123.  
  124. print3:
  125.         dec     al
  126.         jnz     print3
  127.  
  128.         loop    print2                  ;wait for whole timeout
  129.         stc                             ;set carry for timeout
  130.         jmp     short print9            ;and exit
  131.  
  132. print5:
  133.         dec     dx                      ;down to data reg
  134.         mov     al,ah                   ;recover char to be sent
  135.         out     dx,al                   ;put it on data lines
  136.         inc     dx                      ;up to control port
  137.         inc     dx
  138.         mov     al,0dh                  ;set strobe low
  139.         out     dx,al
  140.         mov     al,0ch                  ;set strobe high again
  141.         out     dx,al
  142.         clc                             ;show no error
  143.  
  144. print9:
  145.  
  146. ;
  147. ; At this point, CARRY is SET if we were going to the printer and had an
  148. ; I/O error.
  149. ;
  150.  
  151.         jnc     print10                 ;no error
  152.         call    selvideo                ;error, so switch to video
  153.         pop     ax                      ;recover AL
  154.         push    ax
  155.         jmp     print0                  ;go send it to video
  156.  
  157. print10:
  158.         pop     ax
  159.         pop     bx
  160.         pop     cx
  161.         pop     dx
  162.         ret
  163. print   endp
  164.  
  165. ;********************************************************
  166. ;
  167. ; Output binary AL as 2 hex digits
  168. ;
  169. ;********************************************************
  170.  
  171. print_hex proc  near
  172.         push    bx
  173.         push    ax
  174.         mov     bl,al                   ;isolate HO nibble
  175.         shr     bl,1
  176.         shr     bl,1
  177.         shr     bl,1
  178.         shr     bl,1
  179.         and     bx,0fh
  180.         mov     al,hextab[bx]           ;xlit to hex char
  181.         call    print                   ;print 1st char
  182.         pop     ax
  183.         push    ax
  184.         mov     bl,al                   ;isolate LO nibble
  185.         and     bx,0fh
  186.         mov     al,hextab[bx]           ;xlit to hex char
  187.         call    print                   ;print 2nd char
  188.         pop     ax
  189.         pop     bx
  190.         ret
  191. print_hex endp
  192.  
  193. hextab  db      '0123456789ABCDEF'
  194.  
  195. ;********************************************************
  196. ;
  197. ; Output binary word AX as 4 hex digits
  198. ;
  199. ;********************************************************
  200.  
  201. print_word proc near
  202.         xchg    ah,al                   ;get HO half to AL
  203.         call    print_hex               ;print 1st 2 chars
  204.         xchg    ah,al                   ;get LO half back to AL
  205.         call    print_hex               ;print 2nd 2 chars
  206.         ret
  207. print_word endp
  208.  
  209. ;********************************************************
  210. ;
  211. ; Output binary word AX as 4 hex digits, plus a blank
  212. ;
  213. ;********************************************************
  214.  
  215. print_wordb proc near
  216.         push    ax
  217.         call    print_word
  218.         mov     al,' '
  219.         call    print
  220.         pop     ax
  221.         ret
  222. print_wordb endp
  223.  
  224. ;*****************************************
  225. ;
  226. ; Print CRLF.
  227. ;
  228. ;*****************************************
  229.  
  230. crlf    proc    near
  231.         push    ax
  232.         mov     al,0dh
  233.         call    print
  234.         mov     al,0ah
  235.         call    print
  236.         pop     ax
  237.         ret
  238. crlf    endp
  239.  
  240. ;*****************************************
  241. ;
  242. ; Print string at DS:DX, up to "$" character.
  243. ;
  244. ;*****************************************
  245.  
  246. print_line proc near
  247.         push    si
  248.         push    ax
  249.         cld                     ;forward!
  250.         mov     si,dx           ;DS:SI = string
  251.  
  252. print_line2:
  253.         lodsb                   ;get next byte to print
  254.         cmp     al,'$'          ;terminating char?
  255.         jz      print_line9     ;yes, exit
  256.         call    print           ;print this char
  257.         jmp     print_line2     ;continue till "$"
  258.  
  259. print_line9:
  260.         pop     ax
  261.         pop     si
  262.         ret
  263. print_line endp
  264.  
  265. ;*****************************************
  266. ;
  267. ; Print DX (HO), AX (LO) as xxxx:xxxx.
  268. ;
  269. ;*****************************************
  270.  
  271. print_seg proc  near
  272.         push    ax
  273.         mov     ax,dx           ;get HO word first
  274.         call    print_word
  275.         mov     al,':'          ;show seperator too
  276.         call    print
  277.         pop     ax              ;recover LO word
  278.         call    print_word
  279.         ret
  280. print_seg endp
  281.  
  282. ;********************************************************************
  283. ;
  284. ; Print a line at [DX], edited.
  285. ;
  286. ; Line may contain Edit_xxxx escape characters, as defined above.
  287. ;
  288. ;********************************************************************
  289.  
  290. print_edit proc near
  291.         push    si
  292.         push    dx
  293.         push    cx
  294.         push    bx
  295.         push    ax
  296.         mov     si,dx                   ;use DS:SI to read line
  297.         cld                             ;forward!!!
  298.  
  299. print_edit2:
  300.         lodsb                           ;get next byte of line
  301.         cmp     al,Edit_Byte            ;binary byte to expand?
  302.         jnz     print_edit3             ;no
  303.         lodsb                           ;yes, get 8-bit value
  304.         call    print_hex               ;print it as hex
  305.  
  306. print_edit2b:
  307.         mov     al,'H'                  ;tack "H" for HEX after it
  308.  
  309. print_edit2c:
  310.         call    print
  311.         jmp     print_edit2             ;go get next char
  312.  
  313. print_edit3:
  314.         cmp     al,Edit_Word            ;16-bit binary to expand?
  315.         jnz     print_edit4             ;no
  316.         lodsw                           ;yes, get 16-bit word
  317.         call    print_word              ;display as hex
  318.         jmp     print_edit2b            ;follow with 'H' and continue
  319.  
  320. print_edit4:
  321.         cmp     al,Edit_Call            ;call another routine?
  322.         jnz     print_edit5             ;no
  323.         lodsb                           ;yes, get AH argument
  324.         mov     bh,al                   ;save for a nano...
  325.         lodsw                           ;get DX argument
  326.         mov     dx,ax
  327.         lodsw                           ;get address to call
  328.         mov     cx,ax
  329.         mov     ah,bh                   ;recover AH argument to use
  330.         push    si                      ;save our precious SI
  331.         call    cx                      ;call the routine
  332.         pop     si
  333.         jmp     print_edit2             ;go get next char
  334.  
  335. print_edit5:
  336.         cmp     al,Edit_Dec8            ;8-bit decimal value?
  337.         jnz     print_edit6             ;no
  338.         lodsb                           ;yes, get 8-bit byte
  339.         xor     ah,ah                   ;clear HO byte
  340.  
  341. print_edit5b:
  342.         call    print_dec               ;print AX as decimal
  343.         jmp     print_edit2             ;go get next input char
  344.  
  345. print_edit6:
  346.         cmp     al,Edit_Dec16           ;16-bit decimal value?
  347.         jnz     print_edit7             ;no
  348.         lodsw                           ;yes, get 16-bit byte
  349.         jmp     print_edit5b            ;print it and go get next char
  350.  
  351. print_edit7:
  352.         cmp     al,Edit_End             ;end of input string?
  353.         jnz     print_edit2c            ;no, assume ASCII char and print it
  354.  
  355.         pop     ax
  356.         pop     bx
  357.         pop     cx
  358.         pop     dx
  359.         pop     si
  360.         ret
  361. print_edit endp
  362.  
  363.  
  364. ;**************************************************
  365. ;
  366. ; Print AX in decimal, suppressing leading zeroes
  367. ;
  368. ;**************************************************
  369.  
  370. print_dec proc  near
  371.         push    dx
  372.         push    cx
  373.         push    bx
  374.         push    ax
  375.         mov     cx,10                   ;divisor
  376.         xor     dx,dx
  377.         div     cx                      ;DL=units, AX = answer
  378.         mov     bh,dl                   ;save units
  379.         xor     dx,dx
  380.         div     cx                      ;DL=tens, AX = answer
  381.         mov     bl,dl                   ;get tens
  382.         or      bx,03030h               ;make into 2 ASCII digits
  383.         mov     word ptr dec_buf+3,bx
  384.         div     cl                      ;AH=hunds, AL = answer
  385.         mov     bh,ah                   ;save hundreds
  386.         xor     ah,ah
  387.         div     cl                      ;AH=thous, AL = ten_thousands
  388.         mov     bl,ah                   ;get thous
  389.         or      bx,03030h               ;make into 2 ASCII digits
  390.         mov     word ptr dec_buf+1,bx
  391.         or      al,030h                 ;make ten-thousands into ASCII digit
  392.         mov     byte ptr dec_buf,al
  393.  
  394. ;
  395. ; Now edit out leading zeroes by advancing BX to 1st non-zero
  396. ;
  397.  
  398.         mov     bx,offset dec_buf
  399.         mov     cx,4                    ;max # to suppress
  400.  
  401. print_dec2:
  402.         cmp     byte ptr [bx],'0'
  403.         jnz     print_dec5              ;found non-zero, so exit
  404.         inc     bx                      ;up to next digit
  405.         loop    print_dec2
  406.  
  407. print_dec5:
  408.  
  409. ;
  410. ; All set. Print from [BX] on...
  411. ;
  412.  
  413.         mov     dx,bx
  414.         call    print_line
  415.         pop     ax
  416.         pop     bx
  417.         pop     cx
  418.         pop     dx
  419.         ret
  420. print_dec endp
  421.  
  422. dec_buf db      "99999$"
  423.  
  424.  
  425. ;********************************************************************
  426. ;
  427. ; Print one string from a table of possible strings.
  428. ;
  429. ; On entry: AH holds selector
  430. ;           DX holds table address
  431. ;
  432. ; Each table entry is as follows:
  433. ;
  434. ;       db      <selector>,"string",<term>
  435. ;
  436. ; where:
  437. ;       <selector> is 8-bit byte that is compared with AH. If it
  438. ;                   matches, then this string is printed.
  439. ;
  440. ;       "string" is the string to be printed
  441. ;
  442. ;       <term> is the terminating character, as follows:
  443. ;
  444. ;               00H : end of this string
  445. ;               80H : end of this string, and end of table too
  446. ;
  447. ; If no <selector> matches AH, then "????" is printed.
  448. ;
  449. ;********************************************************************
  450.  
  451. table_print proc near
  452.         push    si
  453.         push    dx
  454.         push    cx
  455.         push    bx
  456.         push    ax
  457.         mov     si,dx                   ;use DS:SI to read table
  458.         cld                             ;forward!!!
  459.  
  460. table_print2:
  461.         lodsb                           ;get next selector
  462.         cmp     al,ah                   ;does it match AH?
  463.         jnz     table_print5            ;no, skip to next one
  464.  
  465. table_print3:
  466.  
  467. ;
  468. ; We have found string to print. Output it until a terminator is found.
  469. ;
  470.  
  471.         lodsb                           ;get byte of string
  472.         test    al,07fh                 ;terminator?
  473.         jz      table_print9            ;yes, exit
  474.         call    print                   ;no, print this char
  475.         jmp     table_print3
  476.  
  477. table_print5:
  478.  
  479. ;
  480. ; Not this selector. Skip over string till terminator, then go peek
  481. ; at next selector.
  482. ;
  483.  
  484.         lodsb                           ;get byte of string
  485.         test    al,07fh                 ;terminator?
  486.         jnz     table_print5            ;no, keep skipping
  487.  
  488. ;
  489. ; We have terminator at end of skipped string. It may be end of whole table...
  490. ;
  491.  
  492.         cmp     al,080h                 ;end of table?
  493.         jnz     table_print2            ;no, go check next selector
  494.         mov     dx,offset huh           ;yes, print "????" message cause match not found
  495.         call    print_line
  496.  
  497. table_print9:
  498.         pop     ax
  499.         pop     bx
  500.         pop     cx
  501.         pop     dx
  502.         pop     si
  503.         ret
  504. table_print endp
  505.  
  506. huh     db      "????$"
  507.  
  508. ;*********************************************
  509. ;
  510. ; Issue extra linefeeds if we're going to the printer. This
  511. ; moves the paper up enough to be read.
  512. ;
  513. ; This should be called before any input, and whenever output is
  514. ; generally finished.
  515. ;
  516. ;*********************************************
  517.  
  518. feed    proc    near
  519.         push    ax
  520.         push    cx
  521.         test    prt_flag,0ffh   ;are we going to the printer?
  522.         jz      feed9           ;no, just exit
  523.         mov     cx,num_feeds    ;# linefeeds to do
  524.         jcxz    feed9           ;none, so exit
  525.  
  526. feed2:
  527.         call    crlf
  528.         loop    feed2
  529.  
  530. feed9:
  531.         pop     cx
  532.         pop     ax
  533.         ret
  534. feed    endp
  535.  
  536.         subttl  Menu Handling
  537.         page
  538. ;*********************************************
  539. ;
  540. ; Get uppercase keyboard char to AL. AH is clobbered.
  541. ;
  542. ;*********************************************
  543.  
  544. key     proc    near
  545.         mov     ah,0            ;use ROM BIOS to read keyboard
  546.         int     016h
  547.         cmp     al,'a'          ;lowercase char?
  548.         jb      key9            ;no
  549.         cmp     al,'z'
  550.         ja      key9            ;likewise no
  551.         and     al,0dfh         ;yes, convert to uppercase
  552. key9:
  553.         ret
  554. key     endp
  555.  
  556. ;*********************************************
  557. ;
  558. ; Reset all ICT hits to zero, and restart trace buffer
  559. ;
  560. ;*********************************************
  561. zapmsg  db    cr,lf,"Counters zeroed",cr,lf,"$"
  562.  
  563. zap_hits proc   near
  564.         push    si
  565.         push    ax
  566.         push    bx
  567.         push    cx
  568.         mov     cx,number_icts          ;Number of ICT's
  569.         xor     si,si                   ;start with # 0
  570.         cli                             ;no interrupts!
  571.  
  572. zap_hits2:
  573.         mov     bx,ict_index[si]        ;[BX] --> ICT
  574.         mov     [bx].ICT_hits,0
  575.         add     si,2                    ;up to next ICT
  576.         loop    zap_hits2               ;till we've done all of them
  577.  
  578.         mov     trace_curr,offset trace_table
  579.         sti                             ;interrupts OK now
  580.         push    dx
  581.         mov     dx,offset zapmsg
  582.         call    print_line
  583.         pop     dx
  584.         pop     cx
  585.         pop     bx
  586.         pop     ax
  587.         pop     si
  588.         ret
  589. zap_hits endp
  590.  
  591. ;**********************************************
  592. ;
  593. ; Pick ICT's with which to do something.
  594. ;
  595. ; This is called to select ICT for various operations.
  596. ;
  597. ; On entry, DX holds address of question (no CRLF's) to be asked.
  598. ;
  599. ; Returns: CARRY SET if user selected ABORT to cancel the caller's operation
  600. ;
  601. ;          CARRY CLEAR if AL has been set to 8-bit pattern, with each
  602. ;          bit from 0 to 7 representing an ICT (0-7) that was selected.
  603. ;
  604. ;**********************************************
  605.  
  606. pick_ict proc   near
  607.         push    bx
  608.         push    cx
  609.         push    dx
  610.         mov     byte ptr pick_map,0     ;init to nobody selected
  611.  
  612. pick_ict1:
  613.  
  614. ;
  615. ; Put up our selection menu
  616. ;
  617.  
  618.         call    crlf
  619.         pop     dx                      ;display caller's question
  620.         push    dx
  621.         call    print_line
  622.         mov     dx,offset pick_menu     ;put up our menu
  623.         call    print_line
  624.  
  625. ;
  626. ; Fill in choices already made, as if he had typed them
  627. ;
  628.  
  629.         mov     cx,number_icts          ;# ICT's
  630.         mov     ah,byte ptr pick_map    ;AH has bitmap
  631.         mov     al,'0'                  ;AL holds ASCII '0' - '7'
  632.  
  633. pick_ict1b:
  634.         test    ah,1                    ;Is this ICT selected?
  635.         jz      pick_ict1c              ;no
  636.         call    print                   ;yes, show corresponding ASCII char
  637.  
  638. pick_ict1c:
  639.         inc     al                      ;Bump ASCII char
  640.         shr     ah,1                    ;get next bit to test
  641.         loop    pick_ict1b              ;till done all 8
  642.         call    feed                    ;eject paper on printer
  643.  
  644. pick_ict2:
  645.  
  646. ;
  647. ; Get and handle next keypress
  648. ;
  649.  
  650.         call    key
  651.         cmp     al,'0'                  ;ICT number?
  652.         jb      pick_ict3               ;no
  653.         cmp     al,'7'
  654.         ja      pick_ict3               ;no
  655.         call    print                   ;yes, echo it
  656.  
  657. ;
  658. ; Convert this ASCII char to bitmap bit, and add to our map
  659. ;
  660.  
  661.         call    bin_to_bit              ;comes back in AL
  662.         or      byte ptr pick_map,al    ;add this new bit into pattern
  663.         jmp     pick_ict2               ;go get next keypress
  664.  
  665. pick_ict3:
  666.         cmp     al,'L'                  ;List ICT's?
  667.         jnz     pick_ict4               ;no
  668.         call    disp_active             ;yes, show all active ICT's
  669.         jmp     pick_ict1               ;give our menu again
  670.  
  671. pick_ict4:
  672.         cmp     al,'R'                  ;Restart?
  673.         jnz     pick_ict5               ;no
  674.         mov     byte ptr pick_map,0     ;yes, clear map
  675.         jmp     pick_ict1               ;give new menu
  676.  
  677. pick_ict5:
  678.         cmp     al,'G'                  ;Go with choices?
  679.         jnz     pick_ict6               ;no
  680.  
  681. pick_ict5b:
  682.         mov     al,byte ptr pick_map    ;yes, get choices as bitmap
  683.         clc                             ;tell caller to use it
  684.         jmp     short pick_ict9         ;exit
  685.  
  686. pick_ict6:
  687.         cmp     al,0dh                  ;Carriage Return?
  688.         jz      pick_ict5b              ;yes, same as "Go"
  689.         cmp     al,'A'                  ;Abort operation?
  690.         jnz     pick_ict7               ;no
  691.  
  692. pick_ict6b:
  693.         stc                             ;tell caller to abort
  694.         jmp     short pick_ict9         ;exit
  695.  
  696. pick_ict7:
  697.         cmp     al,1bh                  ;ESCAPE?
  698.         jz      pick_ict6b              ;yes, same as "Abort"
  699.  
  700. ; ------ Unknown choice
  701.  
  702.         jmp     pick_ict2               ;go get next keypress
  703.  
  704. pick_ict9:
  705.         pop     dx
  706.         pop     cx
  707.         pop     bx
  708.         ret
  709. pick_ict endp
  710.  
  711. pick_menu       db      0dh,0ah
  712.                 db      "0-7 picks ICT   (L)ist ICT's  (A)bort  (R)estart  (G)o with choices"
  713.                 db      0dh,0ah,":$"
  714.  
  715. pick_map        db      0       ;bitmap of selected ICT's
  716.  
  717.  
  718. ;*********************************************
  719. ;
  720. ; Handle "Traces" main menu option
  721. ;
  722. ;*********************************************
  723.  
  724. do_traces proc  near
  725.         push    ax
  726.         push    dx
  727.         mov     dx,offset trace_menu    ;put up our menu
  728.         call    print_line
  729.         call    feed                    ;extra CRLF's for printer
  730.         call    key                     ;get his selection
  731.         cmp     al,'A'                  ;dump All?
  732.         jnz     do_traces2              ;no
  733.         mov     al,0ffh                 ;yes, get bitmap for all ICT's
  734.         jmp     short do_traces7        ;dump 'em
  735.  
  736. do_traces2:
  737.         cmp     al,'S'                  ;Selected ICT's?
  738.         jnz     do_traces9              ;no, so exit
  739.         mov     dx,offset trace_prompt  ;point to question to be used
  740.         call    pick_ict                ;get ICT's as bitmap in AL
  741.         jc      do_traces9              ;user wants to forget about it
  742.  
  743. do_traces7:
  744.  
  745. ;
  746. ; Do dump, with AL holding bitmap of ICT's that are to be included
  747. ;
  748.  
  749.         call    dump_buf                ;with AL already set
  750.  
  751. do_traces9:
  752.         pop     dx
  753.         pop     ax
  754.         ret
  755. do_traces endp
  756.  
  757. trace_menu      db      0dh,0ah
  758.                 db      "Display (A)ll or (S)elected ICTs' traces:$"
  759. trace_prompt    db      "Pick ICT's whose traces are to be included in dump$"
  760.  
  761.  
  762. ;*********************************************
  763. ;
  764. ; Set or Clear F_ENABLE.
  765. ;
  766. ; On entry, AL holds bit value for F_ENABLE (i.e. - ON or OFF).
  767. ;
  768. ; This routine asks user for ICT's to be enabled or disabled.
  769. ;
  770. ;*********************************************
  771.  
  772. do_enable proc  near
  773.         push    si
  774.         push    dx
  775.         push    cx
  776.         push    bx
  777.         push    ax                      ;push him last so we can get to him
  778.  
  779.         mov     dx,offset enable_prompt ;Assume "Enable"
  780.         test    al,F_ENABLE             ;are we enabling?
  781.         jnz     do_enable1              ;yes, we have right message
  782.         mov     dx,offset disable_prompt ;Use "Disable" message
  783.  
  784. do_enable1:
  785.         call    pick_ict                ;get ICT's to be affected
  786.         jc      do_enable9              ;user wants to forget it
  787.         mov     byte ptr enable_map,al  ;save bitmap of ICT's to be done
  788.         xor     si,si                   ;start with ICT #0
  789.         mov     cx,number_icts          ;number of ICT's to look at
  790.  
  791. do_enable2:
  792.         test    byte ptr enable_map,1   ;Should this ICT be done?
  793.         jz      do_enable5              ;no
  794.         mov     bx,ict_index[si]        ;yes, point to ICT
  795.         cli                             ;*** NO INTERRUPTS!!! ***
  796.         pop     ax                      ;get F_ENABLE value
  797.         push    ax
  798.         and     al,F_ENABLE             ;isolate our bit
  799.         mov     ah,[bx].ICT_flags       ;get current flags value
  800.         and     ah,F_ENABLE XOR 0ffh    ;turn off our bit
  801.         or      ah,al                   ;set it per caller's desire
  802.         mov     [bx].ICT_flags,ah       ;replace it in ICT
  803.         STI                             ;*** INTERRUPTS OK NOW ***
  804.  
  805. do_enable5:
  806.         add     si,2                    ;up to next ICT
  807.         shr     byte ptr enable_map,1   ;get next ICT's bitmap bit to Bit 0
  808.         loop    do_enable2              ;till we've looked at all ICT's
  809.  
  810. do_enable9:
  811.         pop     ax
  812.         pop     bx
  813.         pop     cx
  814.         pop     dx
  815.         pop     si
  816.         ret
  817. do_enable endp
  818.  
  819. enable_prompt   db      "Pick ICT's to have tracing ENABLED$"
  820. disable_prompt  db      "Pick ICT's to have tracing DISABLED$"
  821. enable_map      db      0               ;bitmap of ICT's to be altered
  822.  
  823.  
  824.  
  825.  
  826. ;*********************************************
  827. ;
  828. ; Toggle F_FCB in some ICT's.
  829. ;
  830. ;*********************************************
  831.  
  832. do_fcb proc     near
  833.         push    si
  834.         push    dx
  835.         push    cx
  836.         push    bx
  837.         push    ax                      ;push him last so we can get to him
  838.  
  839.         mov     dx,offset fcb_toggle
  840.         call    pick_ict                ;get ICT's to be affected
  841.         jc      do_fcb9                 ;user wants to forget it
  842.         xor     si,si                   ;start with ICT #0
  843.         mov     cx,number_icts          ;number of ICT's to look at
  844.  
  845. do_fcb2:
  846.         test    al,1                    ;Should this ICT be done?
  847.         jz      do_fcb5                 ;no
  848.         mov     bx,ict_index[si]        ;yes, point to ICT
  849.         xor     [bx].ICT_flags,F_FCB    ;toggle current setting
  850.  
  851. do_fcb5:
  852.         add     si,2                    ;up to next ICT
  853.         shr     al,1                    ;get next ICT's bitmap bit to Bit 0
  854.         loop    do_fcb2                 ;till we've looked at all ICT's
  855.  
  856. do_fcb9:
  857.         pop     ax
  858.         pop     bx
  859.         pop     cx
  860.         pop     dx
  861.         pop     si
  862.         ret
  863. do_fcb endp
  864.  
  865. fcb_toggle      db      "Pick ICT's to have F_FCB toggled$"
  866.  
  867.         subttl  Reporting Routines
  868.         page
  869. ;**************************************************
  870. ;
  871. ; Dump trace buffer for ICT's represented by bitmap in AL.
  872. ;
  873. ; If bit n in AL is set, then ICT n's trace records are to be included
  874. ; in dump.
  875. ;
  876. ;**************************************************
  877.  
  878.  
  879. dump_buf proc   near
  880.         push    di
  881.         push    si
  882.         push    dx
  883.         push    cx
  884.         push    bx
  885.         push    ax                      ;push bitmap last so that we can get to it
  886.         xor     di,di                   ;di is printed line counter
  887.         mov     si,offset trace_table   ;start at front of buf
  888.  
  889. dump_buf2:
  890.         cmp     si,trace_curr            ;done whole buffer?
  891.         jae     dump_buf9               ;yes, exit
  892.  
  893. ;
  894. ; Let a keypress interrupt us
  895. ;
  896.  
  897.         mov     ah,1                    ;ROM BIOS "Check for keypress" func
  898.         int     016h                    ;keypress present?
  899.         jnz     dump_buf9               ;yes, exit
  900.  
  901.         mov     al,[si].B_type          ;get ICT #
  902.         call    bin_to_bit              ;convert to bitmap bit
  903.         pop     bx                      ;peek at caller's requested bitmap
  904.         push    bx
  905.         and     bl,al                   ;is this ICT included in caller's bitmap?
  906.         jz      dump_buf5               ;no, skip it
  907.  
  908. ;
  909. ; See if it's time for title line
  910. ;
  911.  
  912.         test    di,07h                  ;every 8 lines
  913.         jnz     dump_buf4               ;not time for title line
  914.         mov     dx,offset dump_title    ;print title line
  915.         call    print_line
  916.  
  917. dump_buf4:
  918.         call    dump_rec                ;dump this record
  919.         inc     di                      ;bump # lines printed
  920.  
  921. dump_buf5:
  922.  
  923. ;
  924. ; Skip over this record, to next one. To do that, we need to know what
  925. ; type of record it is, so that we know how big a record
  926. ; we have to skip over.
  927. ;
  928.  
  929.         mov     bl,[si].B_type          ;get trace record type
  930.         and     bx,11110000b            ;isolate type itself
  931.         shr     bx,1                    ;develop type times 2
  932.         shr     bx,1
  933.         shr     bx,1
  934.         add     si,rec_sizes[bx]        ;add record size to current pointer
  935.         jmp     dump_buf2               ;continue till buffer exhausted
  936.  
  937. dump_buf9:
  938.         pop     ax
  939.         pop     bx
  940.         pop     cx
  941.         pop     dx
  942.         pop     si
  943.         pop     di
  944.         ret
  945. dump_buf endp
  946.  
  947. dump_title      db      0dh,0ah
  948.                 db      0dh,0ah
  949.                 db      "INT #    AX   BX   CX   DX   ES   DS   SI   DI   BP   SS   SP   CS:IP"
  950.                 db      0dh,0ah
  951.                 db      "--- --   ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---------$"
  952.  
  953. ;***********************************************
  954. ;
  955. ; Given binary number (0-7) in AL, return bitmap in AL with corresponding
  956. ; bit (Bit 0 thru Bit 7) set.
  957. ;
  958. ; AH is zeroed.
  959. ;
  960. ;***********************************************
  961.  
  962. bin_to_bit proc near
  963.         mov     ah,al           ;AH is counter, from 7 to 0
  964.         mov     al,1            ;AL is bitmap, Bit 0 to Bit 7
  965.         and     ah,7            ;constrain input
  966.         jz      bin_to_bit9     ;binary was 0, so return with Bit 0 set
  967.  
  968. bin_to_bit3:
  969.         add     al,al           ;shift bitmap left 1 bit
  970.         dec     ah              ;dec count by one
  971.         jnz     bin_to_bit3
  972.  
  973. bin_to_bit9:
  974.         ret
  975. bin_to_bit endp
  976.  
  977. ;***********************************************
  978. ;
  979. ; Dump trace record at [SI]. This routine prints the common
  980. ; header information, then calls specific routines to expand
  981. ; details.
  982. ;
  983. ;***********************************************
  984.  
  985. dump_rec proc   near
  986.         push    si
  987.         push    dx
  988.         push    cx
  989.         push    bx
  990.         push    ax
  991.  
  992.         call    crlf
  993.         mov     al,[si].B_int           ;get Interrupt #
  994.         call    print_hex               ;show interrupt #
  995.         mov     al,'H'
  996.         call    print
  997.         mov     al,' '
  998.         call    print
  999.         mov     al,[si].B_type          ;get ICT #
  1000.         and     al,0fh                  ;less than 15
  1001.         call    print_hex               ;show interrupt number
  1002.         mov     al,' '
  1003.         call    print                   ;print a space
  1004.         mov     bl,[si].B_type          ;get trace type
  1005.         and     bx,11110000b            ;isolate type of trace
  1006.         shr     bx,1                    ;develop type times 2
  1007.         shr     bx,1
  1008.         shr     bx,1
  1009.         mov     bx,word ptr dump_table[bx]
  1010.         call    bx                      ;call proper specific routine
  1011.         pop     ax
  1012.         pop     bx
  1013.         pop     cx
  1014.         pop     dx
  1015.         pop     si
  1016.         ret
  1017. dump_rec endp
  1018.  
  1019. ;
  1020. ; Table of routines to handle various record types
  1021. ;
  1022.  
  1023. dump_table      label   word
  1024.                 dw      offset dump_before      ;record type 0 = BEFORE
  1025.                 dw      offset dump_after       ;record type 1 = AFTER
  1026.                 dw      offset dump_fcb         ;record type 2 = FCB
  1027.                 dw      offset dump_asciiz      ;record type 3 = ASCIIZ
  1028.  
  1029. ;***********************************************
  1030. ;
  1031. ; Dump BEFORE record at [SI]
  1032. ;
  1033. ;***********************************************
  1034.  
  1035. dump_before proc near
  1036.         push    si
  1037.         push    dx
  1038.         push    cx
  1039.         push    bx
  1040.         push    ax
  1041.         mov     al,'B'                  ;Display "B" for BEFORE
  1042.         call    print
  1043.         mov     al,' '                  ;plus blank after
  1044.         call    print
  1045.         mov     ax,[si].B_ax
  1046.         call    print_wordb
  1047.         mov     ax,[si].B_bx
  1048.         call    print_wordb
  1049.         mov     ax,[si].B_cx
  1050.         call    print_wordb
  1051.         mov     ax,[si].B_dx
  1052.         call    print_wordb
  1053.         mov     ax,[si].B_es
  1054.         call    print_wordb
  1055.         mov     ax,[si].B_ds
  1056.         call    print_wordb
  1057.         mov     ax,[si].B_si
  1058.         call    print_wordb
  1059.         mov     ax,[si].B_di
  1060.         call    print_wordb
  1061.         mov     ax,[si].B_bp
  1062.         call    print_wordb
  1063.         mov     ax,[si].B_ss
  1064.         call    print_wordb
  1065.         mov     ax,[si].B_sp
  1066.         call    print_wordb
  1067.         mov     dx,[si].B_cs
  1068.         mov     ax,[si].B_ip
  1069.         call    print_seg
  1070.  
  1071. ;
  1072. ; Try to interpret this BEFORE record, to make reading easier
  1073. ;
  1074.  
  1075.         call    interp
  1076.         pop     ax
  1077.         pop     bx
  1078.         pop     cx
  1079.         pop     dx
  1080.         pop     si
  1081.         ret
  1082. dump_before endp
  1083.  
  1084. ;***********************************************
  1085. ;
  1086. ; Dump AFTER record at [SI]
  1087. ;
  1088. ;***********************************************
  1089.  
  1090. dump_after proc near
  1091.         push    si
  1092.         push    dx
  1093.         push    cx
  1094.         push    bx
  1095.         push    ax
  1096.         mov     al,'A'                  ;Display "A" for AFTER
  1097.         call    print
  1098.         mov     al,' '                  ;plus blank after
  1099.         call    print
  1100.         mov     ax,[si].A_ax
  1101.         call    print_wordb
  1102.         mov     ax,[si].A_bx
  1103.         call    print_wordb
  1104.         mov     ax,[si].A_cx
  1105.         call    print_wordb
  1106.         mov     ax,[si].A_dx
  1107.         call    print_wordb
  1108.         mov     ax,[si].A_es
  1109.         call    print_wordb
  1110.         mov     ax,[si].A_ds
  1111.         call    print_wordb
  1112.         mov     ax,[si].A_si
  1113.         call    print_wordb
  1114.         mov     ax,[si].A_di
  1115.         call    print_wordb
  1116.         mov     ax,[si].A_bp
  1117.         call    print_wordb
  1118.  
  1119. ;
  1120. ; Now expand flags byte for clarity
  1121. ;
  1122.  
  1123.         mov     dx,[si].A_flags         ;hold flags in DX
  1124.         mov     si,offset dump_flags    ;SI = next flag's name
  1125.         mov     bx,0fd5h                ;mask of valid bits in flags word
  1126.         mov     cx,12                   ;# bits to walk through
  1127.         cld                             ;forward!!!
  1128.  
  1129. dump_after2:
  1130.         test    bx,1                    ;is this a valid flag bit?
  1131.         jz      dump_after4             ;no, move to next one
  1132.         lodsb                           ;yes, get next name
  1133.         test    dx,1                    ;is bit set?
  1134.         jnz     dump_after3             ;yes, use name
  1135.         mov     al,' '                  ;no, use blank
  1136.  
  1137. dump_after3:
  1138.         call    print                   ;print flag name or space
  1139.  
  1140. dump_after4:
  1141.         shr     dx,1                    ;shift flags so next flag is in bit 0
  1142.         shr     bx,1                    ;ditto for mask
  1143.         loop    dump_after2             ;till done all 12 bits
  1144.  
  1145.         pop     ax
  1146.         pop     bx
  1147.         pop     cx
  1148.         pop     dx
  1149.         pop     si
  1150.         ret
  1151. dump_after endp
  1152.  
  1153. dump_flags      db      "CPAZSTIDO"
  1154.  
  1155.  
  1156. ;***********************************************
  1157. ;
  1158. ; Dump FCB record at [SI]
  1159. ;
  1160. ;***********************************************
  1161.  
  1162. dump_fcb proc near
  1163.         push    si
  1164.         push    dx
  1165.         push    cx
  1166.         push    bx
  1167.         push    ax
  1168.         mov     al,[si].FCB_drive       ;display drive # as number
  1169.         mov     byte ptr fcb_drv,al
  1170.         mov     dx,offset fcb_line      ;and put up rest of header
  1171.         call    print_edit
  1172.         add     si,3                    ;skip to filename field
  1173.         mov     cx,8                    ;max # chars to display
  1174.         cld                             ;forward!!!
  1175.  
  1176. dump_fcb2:
  1177.         lodsb                           ;get byte of filename
  1178.         cmp     al,020h                 ;control char or blank?
  1179.         jbe     dump_fcb3b              ;yes, we're done with name
  1180.         call    print                   ;no, display char as-is
  1181.         loop    dump_fcb2               ;till 8 done or early exit
  1182.         jmp     short dump_fcb4
  1183.  
  1184. dump_fcb3:                              ;skip over rest of filename
  1185.         lodsb
  1186.  
  1187. dump_fcb3b:
  1188.         loop    dump_fcb3
  1189.  
  1190. dump_fcb4:                              ;output extension too
  1191.         mov     al,'.'                  ;seperate it with period
  1192.         call    print
  1193.         mov     cx,3                    ;# extension bytes to print
  1194.  
  1195. dump_fcb5:
  1196.         lodsb                           ;get byte of extension
  1197.         cmp     al,020h                 ;control char?
  1198.         jb      dump_fcb6               ;yes, skip it
  1199.         call    print                   ;no, use as-is
  1200.  
  1201. dump_fcb6:
  1202.         loop    dump_fcb5
  1203.         pop     ax
  1204.         pop     bx
  1205.         pop     cx
  1206.         pop     dx
  1207.         pop     si
  1208.         ret
  1209. dump_fcb endp
  1210.  
  1211.  
  1212. fcb_line        label   byte
  1213.                 db      "FCB Drive:"
  1214.                 db      Edit_Dec8
  1215. fcb_drv         db      0
  1216.                 db      " Filename: "
  1217.                 db      Edit_End
  1218.  
  1219. ;***********************************************
  1220. ;
  1221. ; Dump ASCIIZ record at [SI]
  1222. ;
  1223. ;***********************************************
  1224.  
  1225. dump_asciiz proc near
  1226.         push    si
  1227.         push    dx
  1228.         push    cx
  1229.         push    bx
  1230.         push    ax
  1231.         mov     dx,offset asciiz_line   ;put up header
  1232.         call    print_line
  1233.         add     si,2                    ;skip to start of ASCIIZ text
  1234.         mov     cx,size ASCIIZ          ;max # chars to display
  1235.         sub     cx,2                    ;(minus 2 for header)
  1236.         cld                             ;forward!!!
  1237.  
  1238. dump_asciiz5:
  1239.         lodsb                           ;get byte of extension
  1240.         or      al,al                   ;NUL terminator?
  1241.         jz      dump_asciiz9            ;yes, exit
  1242.         cmp     al,020h                 ;control char?
  1243.         jb      dump_asciiz6            ;yes, skip it
  1244.         call    print                   ;no, use as-is
  1245.  
  1246. dump_asciiz6:
  1247.         loop    dump_asciiz5
  1248.  
  1249. dump_asciiz9:
  1250.         pop     ax
  1251.         pop     bx
  1252.         pop     cx
  1253.         pop     dx
  1254.         pop     si
  1255.         ret
  1256. dump_asciiz endp
  1257.  
  1258.  
  1259. asciiz_line     label   byte
  1260.                 db      "ASCIIZ: $"
  1261.  
  1262.  
  1263. ;*****************************************
  1264. ;
  1265. ; Display what we know about ICT # AL (0-7).
  1266. ;
  1267. ;*****************************************
  1268.  
  1269. ict_dump proc   near
  1270.         push    dx
  1271.         push    bx
  1272.         push    ax
  1273.  
  1274.         and     ax,number_icts*2-1      ;edit ICT #
  1275.         mov     bx,ax                   ;get ICT # times 2
  1276.         shl     bx,1                    ;divide by 2
  1277.         mov     bx,ict_index[bx]        ;[BX] --> ICT itself
  1278.  
  1279.         mov     byte ptr ict_msgno,al   ;insert it into message
  1280.         mov     dx,offset ict_msg1      ;"ICT #n at ..."
  1281.         call    print_edit
  1282.  
  1283.         mov     dx,ds                   ;display seg:offset of ICT
  1284.         mov     ax,bx
  1285.         call    print_seg
  1286.  
  1287.         mov     dx,offset ict_ena       ;show whether enabled or disabled
  1288.         test    [bx].ICT_flags,F_ENABLE
  1289.         jnz     ict_dump2               ;got right message
  1290.         mov     dx,offset ict_dis       ;get other message
  1291.  
  1292. ict_dump2:
  1293.         call    print_line              ;display "ENABLED" or "DISABLED"
  1294.  
  1295.         mov     dx,offset ict_msg2      ;"INT xxH "
  1296.         call    print_line
  1297.         mov     al,[bx].ICT_intnum      ;display interrupt #
  1298.         call    print_hex
  1299.  
  1300.         mov     dx,offset ict_msg3      ;"AH range ll/hh"
  1301.         call    print_line
  1302.         mov     al,[bx].ICT_AH_lo       ;display AH range lower limit
  1303.         call    print_hex
  1304.         mov     al,'/'                  ;add seperator
  1305.         call    print
  1306.         mov     al,[bx].ICT_AH_hi       ;display AH range upper limit
  1307.         call    print_hex
  1308.  
  1309.         mov     al,'*'                  ;display '*' if FCB/ASCIIZ set
  1310.         test    [bx].ICT_flags,F_FCB
  1311.         jnz     ict_dump3               ;it's set
  1312.         mov     al,' '                  ;not set, so use blank
  1313.  
  1314. ict_dump3:
  1315.         call    print
  1316.  
  1317.         mov     dx,offset ict_msg4      ;"Exit: RET/RET2/IRET"
  1318.         call    print_line
  1319.         mov     al,[bx].ICT_flags       ;interpret exit type
  1320.         mov     dx,offset ict_exit      ;get to first 6-char message
  1321.         test    al,F_RET
  1322.         jz      ict_dump5               ;not this one
  1323.         call    print_line
  1324.  
  1325. ict_dump5:
  1326.         add     dx,6                    ;up to next 6-char exit name
  1327.         test    al,F_RET2
  1328.         jz      ict_dump6               ;not this one
  1329.         call    print_line
  1330.  
  1331. ict_dump6:
  1332.         add     dx,6                    ;up to next 6-char exit name
  1333.         test    al,F_IRET
  1334.         jz      ict_dump7               ;not this one
  1335.         call    print_line
  1336.  
  1337. ict_dump7:
  1338.         mov     dx,offset ict_msg4a     ;"Hits: "
  1339.         call    print_line
  1340.         mov     ax,[bx].ICT_hits
  1341.         call    print_dec
  1342.  
  1343.         pop     ax
  1344.         pop     bx
  1345.         pop     dx
  1346.         ret
  1347.  
  1348. ict_msg1        db      0dh,0ah,"ICT# ",edit_dec8
  1349. ict_msgno       db      ?," ",edit_end
  1350.  
  1351. ict_msg1a       db      " @ $"
  1352. ict_msg2        db      " INT $"
  1353. ict_msg3        db      "H AH:$"
  1354. ict_msg4        db      " Exit:$"
  1355. ict_msg4a       db      "Hits: $"
  1356. ict_exit        db      "RET  $"        ;6-char exit type names
  1357.                 db      "RET2 $"
  1358.                 db      "IRET $"
  1359. ict_ena         db      " ENABLED $"
  1360. ict_dis         db      " DISABLED$"
  1361.  
  1362. ict_dump endp
  1363.  
  1364.  
  1365. ;*********************************************
  1366. ;
  1367. ; Display all active ICT's
  1368. ;
  1369. ;*********************************************
  1370.  
  1371. disp_active     proc    near
  1372.         push    si
  1373.         push    ax
  1374.         push    bx
  1375.         push    cx
  1376.  
  1377.         mov     cx,number_icts          ;Number of ICT's
  1378.         xor     si,si                   ;start with # 0
  1379.  
  1380. disp_active2:
  1381.         mov     bx,ict_index[si]        ;[BX] --> ICT
  1382.         test    [bx].ICT_flags,F_ACTIVE ;Is this ICT active?
  1383.         jz      disp_active5            ;no, skip it
  1384.         mov     ax,si                   ;yes, develop ICT # 0-7
  1385.         shr     ax,1                    ;divide by 2
  1386.         call    ict_dump                ;display it
  1387.  
  1388. disp_active5:
  1389.         add     si,2                    ;up to next ICT
  1390.         loop    disp_active2            ;till we've done all of them
  1391.         pop     cx
  1392.         pop     bx
  1393.         pop     ax
  1394.         pop     si
  1395.         ret
  1396. disp_active endp
  1397.  
  1398.  
  1399. ;*****************************************
  1400. ;
  1401. ;    call previous PrtSc routine
  1402. ;
  1403. ;*****************************************
  1404.  
  1405.          db      "prtsc"                ;eyecatcher
  1406. prt_sc   proc    near
  1407.          push    ax
  1408.          push    es
  1409.  
  1410.          mov     ax,050h                 ;set ES to 0050:0000
  1411.          mov     es,ax                   ;(the print-screen control byte)
  1412.          mov     byte ptr es:[0],0       ;mark us not busy now
  1413.  
  1414.          pushf
  1415.          call    old_int_5
  1416.  
  1417.          mov     byte ptr es:[0],1       ;mark us busy now
  1418.          pop     es
  1419.          pop     ax
  1420.          ret
  1421. prt_sc   endp
  1422.  
  1423.  
  1424. code    ends
  1425.         end    
  1426.  
  1427.